
import { deleteFile, getAllFile,uploadFile } from "@/api/file"
import { message } from "antd"
import { AxiosResponse } from "axios"
import { Dispatch } from "redux"
import { FILEMAN } from "../constant"


export const FileManner = (data: PageData): any => {
    return async (dispatch: Dispatch) => {
        const res = await getAllFile(data)
        if (res.code == 1) {
            dispatch({ type: FILEMAN, data: res.data })
            return res
        } else {
            return "error"
        }
    }
}


export const uploadFileAct = async (formData: FormData) => {
    const res = await uploadFile(formData)
    if (res.code == 1) {
       message.success("上传文件成功")
    }else{
        message.error(res.msg||"上传文件失败")
    }
}


export const deleteFileAct = async (id:number) =>{
    const res =await deleteFile(id)
    if(res.code == 1){
        message.success("删除成功")
       return "success"
    }else{
        message.error(res.msg||"删除失败")
        return "error"
    }
}